package com.ruoyi.web.controller.market.product;

import java.util.List;
import java.util.Map;

import com.ruoyi.db.domain.ProductInfo;
import com.ruoyi.product.service.IProductInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.ProductProfit;
import com.ruoyi.product.service.IProductProfitService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.ProductProfitWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * profitController
 * 
 * @author ruoyi
 * @date 2022-08-31
 */
@Controller
@RequestMapping("/product/profit")
public class ProductProfitController extends BaseController
{
    private String prefix = "product/profit";

    @Autowired
    private IProductProfitService productProfitService;
    @Autowired
    private IProductInfoService productInfoService;

    @RequiresPermissions("product:profit:view")
    @GetMapping()
    public String profit(ModelMap mmap)
    {
        // 产品信息
        List<Map<String, Object>> productMapList = productInfoService.listMap(new ProductInfo());
        mmap.put("productList", productMapList);

        return prefix + "/profit";
    }

    /**
     * 查询profit列表
     */
    @RequiresPermissions("product:profit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductProfit productProfit)
    {
        startPage();
        List<Map<String, Object>> mapList = productProfitService.selectProductProfitListMap(productProfit);
        mapList = new ProductProfitWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出profit列表
     */
    @RequiresPermissions("product:profit:export")
    @Log(title = "profit", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductProfit productProfit)
    {
        List<ProductProfit> list = productProfitService.selectProductProfitList(productProfit);
        ExcelUtil<ProductProfit> util = new ExcelUtil<ProductProfit>(ProductProfit.class);
        return util.exportExcel(list, "profit数据");
    }

    /**
     * 新增profit
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存profit
     */
    @RequiresPermissions("product:profit:add")
    @Log(title = "profit", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductProfit productProfit)
    {
        return toAjax(productProfitService.insertProductProfit(productProfit));
    }

    /**
     * 修改profit
     */
    @RequiresPermissions("product:profit:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ProductProfit productProfit = productProfitService.selectProductProfitById(id);
        mmap.put("productProfit", productProfit);
        return prefix + "/edit";
    }

    /**
     * 修改保存profit
     */
    @RequiresPermissions("product:profit:edit")
    @Log(title = "profit", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductProfit productProfit)
    {
        return toAjax(productProfitService.updateProductProfit(productProfit));
    }

    /**
     * 删除profit
     */
    @RequiresPermissions("product:profit:remove")
    @Log(title = "profit", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productProfitService.deleteProductProfitByIds(ids));
    }
}
